﻿using System;

namespace GraphicsFramework.Entity
{
    public class Point2F
    {
        private float x;
        private float y;

        /// <summary>
        /// Contains class constructors
        /// </summary>
        #region "Constructors"

        public Point2F()
        {
            x = 0;
            y = 0;
        }

        public Point2F(float x, float y)
        {
            this.x = x;
            this.y = y;
        }

        public Point2F Clone()
        {
            return new Point2F(x, y);
        }

        #endregion

        /// <summary>
        /// Contains methods and functions
        /// </summary>
        #region "Methods & Functions"

        public void Move(Entity.Point2F move)
        {
            x += move.x;
            y += move.y;
        }

        public void Snap(float snapvaluex, float snapvaluey)
        {
            x = (int)Math.Round(x / snapvaluex) * snapvaluex;
            y = (int)Math.Round(y / snapvaluey) * snapvaluey;
        }

        public bool IsEqual(float x, float y)
        {
            if ((this.x == x) &&
                (this.y == y))
            {
                return true;
            }

            return false;
        }

        public bool IsEqual(float x, float y, int precision)
        {
            if ((Math.Round(this.x, precision) == Math.Round(x, precision)) &&
                (Math.Round(this.y, precision) == Math.Round(y, precision)))
            {
                return true;
            }

            return false;
        }

        public bool IsEqual(Point2F point)
        {
            if ((this.x == point.x) &&
                (this.y == point.y))
            {
                return true;
            }

            return false;
        }

        public bool IsEqual(Point2F point, int precision)
        {
            if ((Math.Round(this.x, precision) == Math.Round(point.x, precision)) &&
                (Math.Round(this.y, precision) == Math.Round(point.y, precision)))
            {
                return true;
            }

            return false;
        }

        public static bool WithinTolerance(float value, float compare, float tolerance)
        {
            if (((value - tolerance) <= compare) && ((value + tolerance) >= compare))
                return true;

            return false;
        }

        #endregion

        /// <summary>
        /// Contains class properties
        /// </summary>
        #region "Properties"

        public float X
        {
            get { return x; }
            set { x = value; }
        }

        public float Y
        {
            get { return y; }
            set { y = value; }
        }

        public override string ToString()
        {
            return string.Format("X = {0}, Y = {1}", x, y);
        }

        #endregion

    }
}
